package ntu.metaweb.storage;

import java.io.IOException;

import rice.p2p.commonapi.Endpoint;
import rice.p2p.commonapi.rawserialization.InputBuffer;
import ntu.metaweb.XMLMarshaller;
import ntu.p2p.dht.DHTContent;
import ntu.p2p.dht.DHTContentDeserializer;

public class MetawebObjectDeserializer implements DHTContentDeserializer {

	@Override
	public DHTContent deserialize(InputBuffer buf, Endpoint endpoint) {
		try {
			int length = buf.readInt();
			byte[] temp = new byte[length];
			buf.read(temp, 0, length);
			return (DHTContent) XMLMarshaller.getInstance().unmarshall(new String(temp));
		} catch (IOException e) {
			return null;
		}
	}

}
